﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace 桌面视频录制
{
    [Serializable]
    public abstract class DrawBrush
    {
        public abstract Brush GetBrush();
        public abstract Brush GetBrush(Matrix matrix);
    }
    [Serializable]
    public class SolidDrawBrush : DrawBrush
    {
        private Color color;
        public SolidDrawBrush(Color color)
        {
            this.color = color;
        }
        public override Brush GetBrush()
        {
            return new SolidBrush(this.color);
        }
        public override Brush GetBrush(Matrix matrix)
        {
            return GetBrush();
        }
    }
    [Serializable]
    public class LinearGradientDrawBrush : DrawBrush
    {
        private Point startPoint;
        private Point endPoint;
        private Color startColor;
        private Color endColor;
        public LinearGradientDrawBrush(Point startPoint, Point endPoint, Color startColor, Color endColor)
        {
            this.startPoint = startPoint;
            this.endPoint = endPoint;
            this.startColor = startColor;
            this.endColor = endColor;
        }
        public override Brush GetBrush()
        {
            return new LinearGradientBrush(startPoint, endPoint, startColor, endColor);
        }
        public override Brush GetBrush(Matrix matrix)
        {
            LinearGradientBrush brush = new LinearGradientBrush(startPoint, endPoint, startColor, endColor);
            brush.Transform = matrix;
            return brush;
        }
    }
    [Serializable]
    public class TextureDrawBrush : DrawBrush
    {
        private Image image;
        private WrapMode warpMode;
        private Rectangle rect;
        public TextureDrawBrush(Image image, WrapMode warpMode, Rectangle rect)
        {
            this.image = image;
            this.warpMode = warpMode;
            this.rect = rect;
        }
        public override Brush GetBrush()
        {
            return new TextureBrush(image, warpMode, rect);
        }
        public override Brush GetBrush(Matrix matrix)
        {
            TextureBrush brush = new TextureBrush(image, warpMode, rect);
            brush.Transform = matrix;
            return brush;
        }
    }
    [Serializable]
    public class HatchDrawBrush : DrawBrush
    {
        private Color foreColor;
        private Color backColor;
        private HatchStyle hatchStyle;
        public HatchDrawBrush(Color foreColor, Color backColor, HatchStyle hatchStyle)
        {
            this.foreColor = foreColor;
            this.backColor = backColor;
            this.hatchStyle = hatchStyle;
        }
        public override Brush GetBrush()
        {
            return new HatchBrush(hatchStyle, foreColor, backColor);
        }
        public override Brush GetBrush(Matrix matrix)
        {
            return GetBrush();
        }
    }
    [Serializable]
    public class PathGradientDrawBrush : DrawBrush
    {
        private Point[] points;
        private Point centerPoint;
        private Color centerColor;
        private Color surroundColor;
        public PathGradientDrawBrush(Point[] points, Point centerPoint, Color centerColor, Color surroundColor)
        {
            this.points = points;
            this.centerPoint = centerPoint;
            this.centerColor = centerColor;
            this.surroundColor = surroundColor;
        }
        public override Brush GetBrush()
        {
            GraphicsPath path = new GraphicsPath();
            path.AddPolygon(points);
            PathGradientBrush pathGradientBrush = new PathGradientBrush(path);
            pathGradientBrush.CenterPoint = centerPoint;
            pathGradientBrush.CenterColor = centerColor;
            pathGradientBrush.SurroundColors = new Color[] { surroundColor };
            path.Dispose();
            return pathGradientBrush;
        }
        public override Brush GetBrush(Matrix matrix)
        {
            GraphicsPath path = new GraphicsPath();
            path.AddPolygon(points);
            PathGradientBrush pathGradientBrush = new PathGradientBrush(path);
            pathGradientBrush.CenterPoint = centerPoint;
            pathGradientBrush.CenterColor = centerColor;
            pathGradientBrush.SurroundColors = new Color[] { surroundColor };
            pathGradientBrush.Transform = matrix;
            path.Dispose();
            return pathGradientBrush;
        }
    }
}
